package com.basic.backend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.basic.backend.mapper.AnalysisResultMapper;
import com.basic.backend.model.dto.analysis.AnalysisStatsDTO;
import com.basic.backend.model.entity.AnalysisResult;
import com.basic.backend.service.AnalysisService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class AnalysisServiceImpl extends ServiceImpl<AnalysisResultMapper, AnalysisResult> implements AnalysisService {



    private final AnalysisResultMapper analysisMapper;
    @Override
    public AnalysisStatsDTO getAnalysisStats() {
        AnalysisStatsDTO stats = new AnalysisStatsDTO();

        // 总检测数
        stats.setTotalChecked(analysisMapper.selectCount(null));

        // 真实文章数: authenticityProbability >= 50
        stats.setRealCount(analysisMapper.selectCount(
                new QueryWrapper<AnalysisResult>()
                        .ge("authenticityProbability", 50) // >=50
        ));

        // 虚假文章数: authenticityProbability < 50
        stats.setFakeCount(analysisMapper.selectCount(
                new QueryWrapper<AnalysisResult>()
                        .lt("authenticityProbability", 50) // <50
        ));

        // AI生成文章数: aiProbability >= 50
        stats.setAiGeneratedCount(analysisMapper.selectCount(
                new QueryWrapper<AnalysisResult>()
                        .ge("aiProbability", 50) // >=50
        ));

        return stats;
    }


    @Override
    public Long countAnalyzedArticles() {
        long count = analysisMapper.countByCondition("1=1");
        return count;
    }
}



